<?php
/*
	申请退款页面
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
cfc('core')->checklogin();
if($_RQ['op']=='list'){
	$return['status']=$this->model('refund')->status;
	$return['params']['status']=0;
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('mid'=>$_SESSION['uid']);
	$params['status']=intval($_RQ['status']);
	$psize=10;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		
	);
	$list=$this->get_list('order_refund',$parameter);
	foreach($list as &$item){
		$item['orderstatus']=pdo_getcolumn('jy_tour_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['orderid']),'status');
	}
	if(!$list){
		exi('none');
	}
	exi($list);
}

if($_RQ['op']=='apply'){
	if($_RQ['postdata']){		
		$post=get_postdata();
		if(!$post['price']){
			$this->model('refund')->check_order_rerefund($post['orderid'],true);
		}
		$params=array(
			'orderid'=>intval($post['orderid']),
			'images'=>$post['images']?ijson_encode($post['images']):'',
			'price'=>$post['price'],
			'content'=>$post['content'],
		);
		$this->model('refund')->refund_create($params);
		exi('申请成功！请耐心等待管理员审核！','','list');
	}
	$orderid=intval($_RQ['orderid']);
	if(!$orderid){
		exi('请先选择订单！','error');
	}
	$fee=$this->model('refund')->check_order_rerefund($orderid);
	$return['order']=$this->pdo_get('order',array('id'=>$orderid),array('price','status'));
	$return['order']['endprice']=$fee;
	$item=array(
		'orderid'=>$orderid,
		'images'=>array(),
		'price'=>$fee,
		'koufee'=>$return['order']['price']-$fee,
		'oldprice'=>$return['order']['price'],
	);
	$return['item']=$item;
	exi($return);
}
/*
	退款商品发货
*/
if($_RQ['op']=='cancel'){
	$post=get_postdata();	
	$id=intval($post['id']);
	if($id){
		$orderid=pdo_getcolumn('jy_tour_order_refund',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']),'orderid');
		$oldstatus=pdo_getcolumn('jy_tour_order',array('id'=>$orderid,'uniacid'=>$_SESSION['uniacid']),'oldstatus');
		$this->pdo_update('order',array('status'=>$oldstatus,'oldstatus'=>0),array('id'=>$orderid));
		pdo_delete('jy_tour_order_refund',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));	
		exi('取消成功！','error','list');
	}else{		
		exi('取消失败！','error');
	}

}